home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SCRN3.ASM < prev    next >
Assembly Source File  |  1987-03-19  |  8KB  |  251 lines

  1.     TITLE    scrn3.asm
  2.  
  3. ;    AUTHOR    Tim Spencer - Compuserve [73657,1400]
  4. ;    DATE    March 17, 1987
  5.  
  6. _TEXT     SEGMENT BYTE PUBLIC 'CODE'
  7. _TEXT    ENDS
  8.  
  9. _DATA     SEGMENT WORD PUBLIC 'DATA'
  10. SCRN    STRUC        ; screen data structure - defined in video.h
  11. off    dw    0    ; offset (cursor position) 
  12. seg    dw    0    ; screen buffer address
  13. port    dw    0    ; status port address
  14. attrib    dw    0    ; attribute to use 
  15. cgacrd    dw    0    ; enable retrace checking if not zero
  16. SCRN     ENDS
  17.  
  18. _DATA    ENDS
  19.  
  20. DGROUP    GROUP _DATA
  21.     ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP, ES:NOTHING
  22.  
  23.  
  24. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  25.  
  26. ;-----------------------------------------------------------------------;
  27. ; scrn_restore - MSC callable function to restore a rectangular area    ;
  28. ;          of the screen buffer.    Checks for vertical retrace    ;
  29. ;         only if the external structure member cga_card is    ;
  30. ;         non-zero. &scrn is the address of that structure.    ;
  31. ;         (see video.h).                        ;
  32. ;                                    ;                                    ;
  33. ; Note:    This procedure uses stosb in retrace checking mode (instead of    ;
  34. ;       movsb) because it stuffs the char/attrib into the screen buffer    ;
  35. ;       slightly faster.                        ;
  36. ;                                    ;
  37. ; Usage:   scrn_restore(left, right, top, bottom, data_buff, &scrn)    ;
  38. ;                                    ;
  39. ;-----------------------------------------------------------------------;
  40. _DATA SEGMENT
  41. restore_args STRUC        ; structure for easy argument reference
  42.     dw    0        ; saved BP value
  43.     dw    0        ; return address
  44. rleft    dw    0        ; rectangular boundries...
  45. rright    dw    0
  46. rtop    dw    0
  47. rbottom    dw    0
  48. mdata    dw    0        ; address of data buffer to write to screen
  49. mstruct    dw    0        ; pointer to SCRN structure(defined in video.h)
  50. restore_args ENDS
  51.  
  52. cga    db    0        ; variable to hold cga_card value
  53. _DATA ENDS
  54.  
  55.     PUBLIC    _scrn_restore
  56.  
  57. _scrn_restore    PROC    NEAR
  58.     push    bp            ; set up frame pointer
  59.     mov    bp,sp        
  60.     push    si            
  61.     push    di
  62.     mov    bx,[bp].mstruct        ; get pointer to SCRN structure
  63.     les    di,dword ptr[bx].off    ; get scrn seg in es, off in di
  64.     mov    dx,[bx].port        ; get status port address
  65.     mov    ax,[bx].cgacrd         ; hold cga status in variable cga
  66.     mov    cga,al
  67.     mov    si,[bp].mdata        ; make si point to data buffer
  68.     mov    bh,byte ptr[bp].rtop    ; top will be incremented until it
  69.     mov    bl,byte ptr[bp].rbottom    ;  is greater than bottom, then exit.
  70.     xor    cx,cx            ; set initial logical cursor position
  71.     mov    cl,bh            ;  by getting top into cx,
  72.     mov    al,80            ;  multiplying by 80,
  73.     mul    cl
  74.     mov    cx,ax
  75.     add    cx,[bp].rleft        ;  adding left.
  76.     shl    cx,1            ;  and multiplying by 2
  77.     mov    di,cx            ;  put result into di 
  78.     mov    cx,[bp].rright        ; get the length of one line into
  79.     sub    cx,[bp].rleft        ;  cx by subtracting left from right
  80.     add    cx,1            ;  adding 1
  81.     push    cx            ;  save it
  82.     mov    ax,79            ; calculate offset from end of line to
  83.     sub    ax,[bp].rright        ;  the start of the next line
  84.     add    ax,[bp].rleft
  85.     shl    ax,1
  86.     push    ax            ;  and save it
  87. write_line:
  88.     cmp    cga,0            ; cga card in use?
  89.     jnz    rwait1            ; yes, go wait
  90.     rep    movsw            ; no, warp speed.
  91.     jmp    short rcheck_pos    ; go check position     
  92. rwait1:
  93.         in      al, dx                  ; wait for end of retrace
  94.         shr     al, 1                   ; test horizontal trace bit
  95.         jc      rwait1            ; loop if still tracing
  96.         cli                             ; disable writus interuptus
  97. rwait2:
  98.         in      al, dx                  ; now wait until the very moment
  99.         shr     al, 1                   ; when the next retrace begins
  100.         jnc     rwait2            ; still waiting...
  101.         mov     al,[si]            ; load the char into al for stosb
  102.         stosb                ; write it and update pointer
  103.         sti                             ; enable interrupts again
  104.     inc    si            ; point si at attribute
  105. rwait3:
  106.         in      al, dx                  ; repeat these steps for the attribute
  107.         shr     al, 1
  108.         jc      rwait3
  109.         cli                             
  110. rwait4:
  111.         in      al, dx                  
  112.         shr     al, 1                   
  113.     jnc     rwait4
  114.         mov     al,[si]            ; load the attribute
  115.         stosb
  116.         sti  
  117.     inc    si            ; point si at next char                           
  118.     loop    rwait1
  119. rcheck_pos:
  120.     pop    ax            ; restore offset to next line start
  121.     pop    cx            ; restore count
  122.     inc    bh            ; is top greater than bottom yet?
  123.     cmp    bh,bl
  124.     ja    rexit            ; yes.
  125.     push    cx            ; no, save count again
  126.     push    ax            ; save line start offset again
  127.     add    di,ax            ; move di to start of next line
  128.     jmp    short write_line    ; write another line
  129. rexit:
  130.     pop    di
  131.     pop    si
  132.     pop    bp
  133.     ret
  134. _scrn_restore    ENDP
  135.  
  136.  
  137.  
  138. ;-----------------------------------------------------------------------;
  139. ; scrn_save - MSC callable function to save a rectangular area of the    ;
  140. ;          screen to a user defined buffer.                 ;
  141. ;                                    ;
  142. ; Usage:    scrn_save(left, right, top, bottom, data_buff, &scrn)    ;
  143. ;-----------------------------------------------------------------------;
  144. _DATA    SEGMENT
  145. save_args STRUC            ; structure for easy argument reference    
  146.     dw    0        ; saved bp value
  147.     dw    0        ; return address
  148. sleft    dw    0        ; rectangular boundries
  149. sright    dw    0        
  150. stop    dw    0
  151. sbottom    dw    0
  152. sbuff    dw    0        ; user defined buffer to hold screen contents
  153. sstruct    dw    0        ; pointer to SCRN structure (see video.h)
  154. save_args ENDS        
  155. _DATA    ENDS
  156.  
  157. scga    db    0        ; store cga true/false value here - must be
  158.                 ; declared outside data segment because es and
  159.                 ; ds are swapped in this function.
  160.  
  161.     PUBLIC    _scrn_save
  162.  
  163. _scrn_save    PROC    NEAR
  164.     push    bp            ; set up frame pointer
  165.     mov    bp,sp    
  166.     push    si            
  167.     push    di
  168.     push    ds
  169.     mov    bx,[bp].mstruct        ; get pointer to SCRN structure
  170.     mov    dx,[bx].port        ; get status port address
  171.     mov    ax,[bx].cgacrd         ; hold cga status in variable scga
  172.     mov    scga,al
  173.     mov    ax,ds
  174.     mov    es,ax            ; get data segment into es 
  175.     mov    di,[bp].sbuff        ;  and offset of user buffer in di    
  176.     mov    ax,[bx].seg        ; get the screen segment and
  177.     mov    ds,ax            ;  put in ds     
  178.     mov    bh,byte ptr[bp].stop    ; top will be incremented until it
  179.     mov    bl,byte ptr[bp].sbottom    ;  is greater than bottom, then exit.
  180.     xor    cx,cx            ; set initial logical cursor position
  181.     mov    cl,bh            ;  by getting top into cx,
  182.     mov    al,80            ;  multiplying by 80,
  183.     mul    cl
  184.     mov    cx,ax
  185.     add    cx,[bp].sleft        ;  adding left.
  186.     shl    cx,1            ;  and multiplying by 2
  187.     mov    si,cx            ;  put result into si 
  188.     mov    cx,[bp].sright        ; get the length of one line into
  189.     sub    cx,[bp].sleft        ;  cx by subtracting left from right
  190.     add    cx,1            ;  adding 1
  191.     push    cx            ;  save it
  192.     mov    ax,79            ; calculate offset from end of line to
  193.     sub    ax,[bp].sright        ;  the start of the next line
  194.     add    ax,[bp].sleft
  195.     shl    ax,1
  196.     push    ax            ;  and save it
  197. read_line:
  198.     cmp    cga,0            ; cga card in use?
  199.     jnz    swait1            ; yes, go wait
  200.     rep    movsw            ; no, warp speed.
  201.     jmp    short scheck_pos    ; go check position     
  202. swait1:
  203.         in      al, dx                  ; wait for end of retrace
  204.         shr     al, 1                   ; test horizontal trace bit
  205.         jc      swait1            ; loop if still tracing
  206.         cli                             ; disable writus interuptus
  207. swait2:
  208.         in      al, dx                  ; now wait until the very moment
  209.         shr     al, 1                   ; when the next retrace begins
  210.         jnc     swait2            ; still waiting...
  211.         mov     al,[si]            ; load the char into al for stosb
  212.         stosb                ; write it and update pointer
  213.         sti                             ; enable interrupts again
  214.     inc    si            ; point si at attribute
  215. swait3:
  216.         in      al, dx                  ; repeat these steps for the attribute
  217.         shr     al, 1
  218.         jc      swait3
  219.         cli                             
  220. swait4:
  221.         in      al, dx                  
  222.         shr     al, 1                   
  223.     jnc     swait4
  224.         mov     al,[si]            ; load the attribute
  225.         stosb
  226.         sti  
  227.     inc    si            ; point si at next char                           
  228.     loop    swait1
  229. scheck_pos:
  230.     pop    ax            ; restore offset to next line start
  231.     pop    cx            ; restore count
  232.     inc    bh            ; is top greater than bottom yet?
  233.     cmp    bh,bl
  234.     ja    sexit            ; yes.
  235.     push    cx            ; no, save count again
  236.     push    ax            ; save line start offset again
  237.     add    si,ax            ; move di to start of next line
  238.     jmp    short read_line        ; write another line
  239. sexit:
  240.     pop    ds
  241.     pop    di
  242.     pop    si
  243.     pop    bp
  244.     ret
  245. _scrn_save    ENDP
  246.  
  247.  
  248. _TEXT    ENDS
  249.  
  250.     END
  251.